﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using NCI.EasyObjects;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using CMS.BLL.Entity;
using CMS.DAL;

namespace CMS.BLL
{
    public class TourDeparture
    {
        public eTourDeparture   Data;

        public TourDeparture()
        {
            Data = new eTourDeparture();
		}

        ~TourDeparture()
        {
		}

		public virtual void Dispose()
        {
		}

        public int DeleteById(int ID)
        {
            int nResult = 0;
            cTourDeparture objDAL = new cTourDeparture();
            try
            {
                objDAL.LoadByPrimaryKey(ID);
                objDAL.MarkAsDeleted();
                objDAL.Save();
                nResult = ID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }

        public void LoadById(int ID)
        {
           cTourDeparture objDAL = new cTourDeparture();
            objDAL.LoadByPrimaryKey(ID);
            ConvertData(objDAL);
        }

        public int Insert()
        {
            int nResult = 0;
           cTourDeparture objInfor = new cTourDeparture(); 
            try
            {
                objInfor.AddNew();
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = objInfor.TourDepartureID ;
            }
            catch
            {
                nResult = 0; 
            }
            return nResult;
        }

        public int Update(int ID)
        {
            int nResult = 0;
            cTourDeparture objInfor = new cTourDeparture();
            try
            {
                objInfor.LoadByPrimaryKey(ID);
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = ID; 
            }
            catch
            {
                nResult = 0; 
            }
            return nResult;
        }

        private void MappingData(cTourDeparture objInfor)
        {
            objInfor.TourID = Data.TourID;
            objInfor.TourDepartureDate = Data.TourDepartureDate;
            objInfor.TourReturnDate = Data.TourReturnDate;
        }

        private void ConvertData(cTourDeparture objInfor)
        {
             Data.TourID = objInfor.TourID;
             Data.TourDepartureDate = objInfor.TourDepartureDate;
             Data.TourReturnDate = objInfor.TourReturnDate;
        }

        public DataTable Search()
        {
            DataTable tbResult = new DataTable();
            cTourDeparture objDAL = new cTourDeparture();
            tbResult = objDAL.Search();
            return tbResult;
        }
    }
}